package com.cjm.one.custom.apps.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.custom.service.CustomGradeService;
import com.cjm.one.model.custom.entity.CustomGrade;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "5-用户等级")
@RequestMapping("/app/customer/grade")
public class AppCustomGradeController
{

    @Resource
    private CustomGradeService customGradeService;

    @GetMapping("/list")
    @Operation(summary = "获取用户等级列表")
    public Result<Page<CustomGrade>> list(@RequestParam(defaultValue = "1") Integer current,
                                          @RequestParam(defaultValue = "10") Integer size) {
        Page<CustomGrade> page = new Page<>(current, size);
        return Result.ok(customGradeService.page(page));
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取用户等级详情")
    public Result<CustomGrade> getInfo(@PathVariable(name = "id") Long id) {
        return Result.ok(customGradeService.getById(id));

    }
    @PostMapping
    @Operation(summary = "创建用户等级")
    public Result<Boolean> create(@RequestBody CustomGrade customGrade) {
        return Result.ok(customGradeService.save(customGrade));
    }
    @PutMapping
    @Operation(summary = "更新用户等级")
    public Result<Boolean> update(@RequestBody CustomGrade customGrade) {
        return Result.ok(customGradeService.updateById(customGrade));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除用户等级")
    public Result<Boolean> delete(@PathVariable(name = "id") Long id) {
        return Result.ok(customGradeService.removeByIdGrade(id));
    }

    @PutMapping("/{id}/{status}/status")
    @Operation(summary = "更新用户等级状态")
    public Result<Boolean> updateStatus(@PathVariable(name = "id") Long id,@PathVariable(name="status")Integer status) {
        return Result.ok(customGradeService.updateStatusById(id,status));
    }
}
